/**
IGroupservice.java * 实现groupservice接口 ，
 */
package com.emode.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.emode.base.BaseDaoImpl;
import com.emode.entity.Bbsusers;
import com.emode.entity.UserSign;
import com.emode.service.SignService;

/**
 * @author emode
 *
 * 2014年12月26日 下午11:09:05

 */
public class SignServiceImpl extends BaseDaoImpl<UserSign> implements SignService {

	@Override
	public boolean ifHasSigned(Serializable id) throws Exception {
		String sql = " select count(1) from user_sign t where DATE_FORMAT(t.sign_time,'%Y%m%d') = DATE_FORMAT(sysdate(),'%Y%m%d')"
				+ " and signer= ?";
		return getSqlCount(sql,id)>0;
	}

	@Override
	public List<UserSign> listSign(String year, String month,Bbsusers user) {
		String queryString = "from UserSign s where DATE_FORMAT(s.signTime,'%Y%c') = " + year + month + " and signer= ? order by s.signTime asc";
		return getListByHQL(queryString,user);
	}

	@Transactional
	public void save(UserSign sign,Bbsusers user) {
		ht.save(sign);
		String hql = "update Bbsusers u set u.signtimes = ?,u.upoint=? where u.uid=?";
		System.out.println("signTimes="+user.getSigntimes()+1+"uid="+user.getUid());
		updateObj(hql,new Object[]{user.getSigntimes()+1,user.getUpoint()+3,user.getUid()});
		
	}
	
	

}
